package com.cyc.basic.util;

import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

public class ExcelExport {

    private HSSFWorkbook wb;
    private String fileName;
	
	public ExcelExport(String fileName) {
        if (wb == null)
            this.wb = new HSSFWorkbook();
        this.fileName = fileName;
    }

	 //导出参数
    public static ExportParams getExportParams(String name) {
        //表格名称,sheet名称,导出版本
        return new ExportParams(name, name, ExcelType.HSSF);
    }

    public void setWorkBook(Workbook wb) {
        this.wb = (HSSFWorkbook) wb;
    }

	public void doExportTwo(String path) throws Exception {
        final OutputStream os = new FileOutputStream(new File(path + "/" + fileName + ".xls"));
        this.wb.write(os);
        os.flush();
        os.close();
    }
}
